package com.baizhi.action;

import com.baizhi.entity.Category;
import com.baizhi.service.CategoryService;
import com.baizhi.service.impl.CategoryServiceImpl;

import java.util.List;

public class CategoryAction {
    private Integer pageNum = 1;
    private Integer pageSize = 3;
    private  Integer totalPage;
    private List<Category> categorys;
    private Category c;
    private CategoryService cs;
    public void setCs(CategoryService cs) {
        this.cs = cs;
    }
    //添加类别
    public String addCategory(){
        int i = cs.addCateogry(c);
        return "addCategoryOK";
    }
    //更新类别
    public String updateCategory(){
        int i = cs.updateCategory(c);
        return  "updateCategoryOK";
    }
    //更新请获取一个类别
    public String getOneCatgory(){
        c = cs.selectById(c.getId());
        return "updateCategoryList";
    }
    //分页查询类别
    public String selectCategoryByPage(){
        int i = cs.totalCategory();
        totalPage = i%pageSize==0 ? i/pageSize:i/pageSize+1;
        categorys = cs.selectCategoryByCondition(pageNum, pageSize);
        return "categorylist";
    }
    //查询全部类别  用于添加商品时的下拉框展示
    public String selectAllCategory(){
        categorys = cs.selectAllCategory();
        return "selectAll";
    }
    public Category getC() {
        return c;
    }

    public void setC(Category c) {
        this.c = c;
    }
    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public List<Category> getCategorys() {
        return categorys;
    }

    public void setCategorys(List<Category> categorys) {
        this.categorys = categorys;
    }

}
